package client;

import java.io.*;
import java.net.*;

class TCPclient {
	
	public static void main(String argv[]) throws Exception {
		
		String modifiedSentence;
		
		BufferedReader inFromUser = 
			new BufferedReader(new InputStreamReader(System.in));
		
		System.out.print("Request which server? ");
		
		String serverHost = inFromUser.readLine();
			
		Socket clientSocket;
		
		try{
			clientSocket = new Socket(serverHost, 1027);
			
			DataOutputStream outToServer = 
				new DataOutputStream(clientSocket.getOutputStream());
			
			BufferedReader inFromServer = 
				new BufferedReader(new
						InputStreamReader(clientSocket.getInputStream()));
			
			String sentence = "request_INIT";			
			outToServer.writeBytes(sentence + '\n');			
			
			int i = 0;
			while(i < 10){
				modifiedSentence = inFromServer.readLine();
				System.out.println("FROM SERVER: " + modifiedSentence);
				i++;
//				sentence = "request_" + i;			
//				outToServer.writeBytes(sentence + '\n');
			}						
					
			sentence = "request_STOP";			
			outToServer.writeBytes(sentence);
				
			clientSocket.close();
		}
		catch (UnknownHostException ex) {
			System.err.println("No service at host " + ex);			
		}
	}
	
}